//
//  HKSubTagCell.m
//  BaiSiBuDeJie
//
//  Created by 胡锦涛 on 2018/12/1.
//  Copyright © 2018 胡锦涛. All rights reserved.
//

#import "HKSubTagCell.h"
#import "HKSubTagItem.h"
#import <UIImageView+WebCache.h>
#import "UIImage+image.h"
@interface HKSubTagCell()
@property (weak, nonatomic) IBOutlet UIImageView *iconView;
@property (weak, nonatomic) IBOutlet UILabel *nameView;
@property (weak, nonatomic) IBOutlet UILabel *numView;

@end
@implementation HKSubTagCell

-(void)setFrame:(CGRect)frame {
    //才是真正给cell赋值
    frame.size.height -=1;
    [super setFrame:frame];
}
- (void)setItem:(HKSubTagItem *)item
{
    _item = item;
    // 设置内容
    _nameView.text = item.theme_name;
    //处理订阅数字
    [self resolveNum];
    HKWeakSelf
    [_iconView sd_setImageWithURL:[NSURL URLWithString:item.image_list] placeholderImage:[UIImage imageNamed:@"defaultUserIcon"] options:SDWebImageFromCacheOnly completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        HKStrongSelf
        self.iconView.image = [image roundImage];
    }];
}
//处理订阅数字
- (void)resolveNum {
    // 判断下有没有>10000
    NSString *numStr = [NSString stringWithFormat:@"%@人订阅",_item.sub_number] ;
    NSInteger num = _item.sub_number.integerValue;
    if (num > 10000) {
        CGFloat numF = num / 10000.0;
        numStr = [NSString stringWithFormat:@"%.1f万人订阅",numF];
        numStr = [numStr stringByReplacingOccurrencesOfString:@".0" withString:@""];
    }
    
    _numView.text = numStr;
}
// 从xib加载就会调用一次
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    // 设置头像圆角,iOS9苹果修复（1.代码设置）
//    _iconView.layer.cornerRadius = _iconView.height/2;
//    _iconView.layer.masksToBounds = YES;
    //(2.Storyboard设置)User Defined Runtime Attributed
    //使用不当，会造成TableView滑动不畅
    //小心别让圆角成了你列表的帧数杀手
    //self.layoutMargins = UIEdgeInsetsZero;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
